<?php

namespace C\M;

use C\L\Model;

class Shipment extends Model
{
    public function initialize()
    {
        $this->setSource('shipments');
    }

    public function beforeValidationOnCreate()
    {
        $date = date('Y-m-d H:i:s');
        $this->created_at = $this->updated_at = $date;

        switch ($this->state) {
            case 'shipped':
                $this->shipped_at = $date;
                break;
            case 'delivered':
                $this->delivered_at = $date;
                break;
            default:
                break;
        }

        return true;
    }

    public function beforeValidationOnUpdate()
    {
        $this->updated_at = date('Y-m-d H:i:s');
        return true;
    }
}
